import {createPinia, defineStore} from 'pinia'
import piniaPluginPersistence from "pinia-plugin-persistedstate";
export const pinia = createPinia();
pinia.use(piniaPluginPersistence);

const useStore = defineStore('questionnaire-store', {
    state: () => {
        return {
            userIsLogin:false,
            userId:'0',
            userinfo:{}
        }
    },
    persist: {
        enabled: true,
        key: 'questionnaire-store',
        storage: localStorage,
        // strategies: [
        //     { storage: localStorage, paths: ['userIsLogin','userId','userinfo'] },
        // ],
    }
})



//是否登录
export function localSetUserLogin(userIsLogin){
    localStorage.setItem('userIsLogin',userIsLogin.toString())
}

export function localGetUserLogin(){
    return localStorage.getItem('userIsLogin') === 'true'
}
export function localClearUserLogin(){
    return localStorage.removeItem('userIsLogin')
}

export function useUserStore(){
    return useStore(pinia)
}

export default useStore